﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WPF_GUI.Commanding;
using System.Windows.Input;

namespace WPF_GUI.ViewModels
{
    public class ManualControlWindowViewModel : ChildWindowViewModel
    {
        public ManualControlWindowViewModel(MainPageViewModel parentViewModel)
            : base (parentViewModel)
        {
            CanClearPlaneForTakeoff24L = true;
            CanClearPlaneForTakeoff24R = true;
            CanClearPlaneForTakeoff25L = true;
            CanClearPlaneForTakeoff25R = true;

            CanClearPlaneForLanding24L = true;
            CanClearPlaneForLanding24R = true;
            CanClearPlaneForLanding25L = true;
            CanClearPlaneForLanding25R = true;
        }

        #region Buttons

        #region Fields

        RelayCommand _acceptSuggestionCommand;
        RelayCommand _clearPlaneForTakeoff24LCommand;
        RelayCommand _clearPlaneForTakeoff24RCommand;
        RelayCommand _clearPlaneForTakeoff25LCommand;
        RelayCommand _clearPlaneForTakeoff25RCommand;
        RelayCommand _clearPlaneForLanding24LCommand;
        RelayCommand _clearPlaneForLanding24RCommand;
        RelayCommand _clearPlaneForLanding25LCommand;
        RelayCommand _clearPlaneForLanding25RCommand;
        RelayCommand _cancelRouteCommand;
        RelayCommand _openLoadScenarioWindowCommand;
        RelayCommand _openManualRouteWindowCommand;

        #endregion // Fields

        #region Button Enablers

        public bool CanSelectAcceptSuggestion { get; set; }
        public bool CanClearPlaneForTakeoff24L { get; set; }
        public bool CanClearPlaneForTakeoff24R { get; set; }
        public bool CanClearPlaneForTakeoff25L { get; set; }
        public bool CanClearPlaneForTakeoff25R { get; set; }
        public bool CanClearPlaneForLanding24L { get; set; }
        public bool CanClearPlaneForLanding24R { get; set; }
        public bool CanClearPlaneForLanding25L { get; set; }
        public bool CanClearPlaneForLanding25R { get; set; }
        public bool CanCancelRoute { get; set; }
        public bool CanOpenLoadScenarioWindow { get; set; }
        public bool CanOpenManualRouteWindow { get; set; }

        #endregion // Button Enablers

        #region Button Command Properties

        public ICommand AcceptSuggestionCommand
        {
            get
            {
                if (_acceptSuggestionCommand == null)
                {
                    _acceptSuggestionCommand = new RelayCommand(
                        param => this.ButtonAcceptSuggestedRoute_Click(),
                        param => this.CanSelectAcceptSuggestion
                        );
                }
                return _acceptSuggestionCommand;
            }
        }

        public ICommand ClearPlaneForTakeoff24LCommand
        {
            get
            {
                if (_clearPlaneForTakeoff24LCommand == null)
                {
                    _clearPlaneForTakeoff24LCommand = new RelayCommand(
                        param => this.ButtonClearPlaneForTakeoff24L_Click(),
                        param => this.CanClearPlaneForTakeoff24L
                        );
                }
                return _clearPlaneForTakeoff24LCommand;
            }
        }

        public ICommand ClearPlaneForTakeoff24RCommand
        {
            get
            {
                if (_clearPlaneForTakeoff24RCommand == null)
                {
                    _clearPlaneForTakeoff24RCommand = new RelayCommand(
                        param => this.ButtonClearPlaneForTakeoff24R_Click(),
                        param => this.CanClearPlaneForTakeoff24R
                        );
                }
                return _clearPlaneForTakeoff24RCommand;
            }
        }

        public ICommand ClearPlaneForTakeoff25LCommand
        {
            get
            {
                if (_clearPlaneForTakeoff25LCommand == null)
                {
                    _clearPlaneForTakeoff25LCommand = new RelayCommand(
                        param => this.ButtonClearPlaneForTakeoff25L_Click(),
                        param => this.CanClearPlaneForTakeoff25L
                        );
                }
                return _clearPlaneForTakeoff25LCommand;
            }
        }

        public ICommand ClearPlaneForTakeoff25RCommand
        {
            get
            {
                if (_clearPlaneForTakeoff25RCommand == null)
                {
                    _clearPlaneForTakeoff25RCommand = new RelayCommand(
                        param => this.ButtonClearPlaneForTakeoff25R_Click(),
                        param => this.CanClearPlaneForTakeoff25R
                        );
                }
                return _clearPlaneForTakeoff25RCommand;
            }
        }

        public ICommand ClearPlaneForLanding24LCommand
        {
            get
            {
                if (_clearPlaneForLanding24LCommand == null)
                {
                    _clearPlaneForLanding24LCommand = new RelayCommand(
                        param => this.ButtonClearPlaneForLanding24L_Click(),
                        param => this.CanClearPlaneForLanding24L
                        );
                }
                return _clearPlaneForLanding24LCommand;
            }
        }

        public ICommand ClearPlaneForLanding24RCommand
        {
            get
            {
                if (_clearPlaneForLanding24RCommand == null)
                {
                    _clearPlaneForLanding24RCommand = new RelayCommand(
                        param => this.ButtonClearPlaneForLanding24R_Click(),
                        param => this.CanClearPlaneForLanding24R
                        );
                }
                return _clearPlaneForLanding24RCommand;
            }
        }

        public ICommand ClearPlaneForLanding25LCommand
        {
            get
            {
                if (_clearPlaneForLanding25LCommand == null)
                {
                    _clearPlaneForLanding25LCommand = new RelayCommand(
                        param => this.ButtonClearPlaneForLanding25L_Click(),
                        param => this.CanClearPlaneForLanding25L
                        );
                }
                return _clearPlaneForLanding25LCommand;
            }
        }

        public ICommand ClearPlaneForLanding25RCommand
        {
            get
            {
                if (_clearPlaneForLanding25RCommand == null)
                {
                    _clearPlaneForLanding25RCommand = new RelayCommand(
                        param => this.ButtonClearPlaneForLanding25R_Click(),
                        param => this.CanClearPlaneForLanding25R
                        );
                }
                return _clearPlaneForLanding25RCommand;
            }
        }

        public ICommand CancelRouteCommand
        {
            get
            {
                if (_cancelRouteCommand == null)
                {
                    _cancelRouteCommand = new RelayCommand(
                        param => this.ButtonCancelRoute_Click(),
                        param => this.CanCancelRoute
                        );
                }
                return _cancelRouteCommand;
            }
        }

        public ICommand OpenLoadScenarioWindowCommand
        {
            get
            {
                if (_openLoadScenarioWindowCommand == null)
                {
                    _openLoadScenarioWindowCommand = new RelayCommand(
                        param => this.ButtonLoadScenario_Click(),
                        param => this.CanOpenLoadScenarioWindow
                        );
                }
                return _openLoadScenarioWindowCommand;
            }
        }

        public ICommand OpenManualRouteWindowCommand
        {
            get
            {
                if (_openManualRouteWindowCommand == null)
                {
                    _openManualRouteWindowCommand = new RelayCommand(
                        param => this.ButtonManualRoute_Click(),
                        param => this.CanOpenManualRouteWindow
                        );
                }
                return _openManualRouteWindowCommand;
            }
        }

        #endregion // Button Command Properties

        #region Button Command Handlers
        
        public void ButtonAcceptSuggestedRoute_Click()
        {
            _parentViewModel.AcceptSuggestedRoute();
        }

        public void ButtonClearPlaneForTakeoff24L_Click()
        {
            _parentViewModel.ClearPlaneForTakeoff(MainPageViewModel._runwayId24L);
        }

        public void ButtonClearPlaneForTakeoff24R_Click()
        {
            _parentViewModel.ClearPlaneForTakeoff(MainPageViewModel._runwayId24R);
        }

        public void ButtonClearPlaneForTakeoff25L_Click()
        {
            _parentViewModel.ClearPlaneForTakeoff(MainPageViewModel._runwayId25L);
        }

        public void ButtonClearPlaneForTakeoff25R_Click()
        {
            _parentViewModel.ClearPlaneForTakeoff(MainPageViewModel._runwayId25R);
        }

        public void ButtonClearPlaneForLanding24L_Click()
        {
            _parentViewModel.ClearPlaneForLanding(MainPageViewModel._runwayId24L);
        }

        public void ButtonClearPlaneForLanding24R_Click()
        {
            _parentViewModel.ClearPlaneForLanding(MainPageViewModel._runwayId24R);
        }

        public void ButtonClearPlaneForLanding25L_Click()
        {
            _parentViewModel.ClearPlaneForLanding(MainPageViewModel._runwayId25L);
        }

        public void ButtonClearPlaneForLanding25R_Click()
        {
            _parentViewModel.ClearPlaneForLanding(MainPageViewModel._runwayId25R);
        }

        public void ButtonCancelRoute_Click()
        {
            _parentViewModel.CancelSelectedRoute();
        }

        public void ButtonLoadScenario_Click()
        {
            _parentViewModel.LoadScenario();
        }

        public void ButtonManualRoute_Click()
        {
            _parentViewModel.EnterManualRoute();
        }

        #endregion // Button Command Handlers

        #endregion // Buttons
    }
}
